from django.db import models


# Create your models here.

class Student(models.Model):
    stu_id = models.IntegerField(primary_key=True)
    stu_pwd = models.CharField(max_length=100, unique=False)
    stu_name = models.CharField(max_length=100, unique=True, null=True)
    # null = true
    stu_phone = models.CharField(max_length=11,unique=True, null=True)
    stu_gender = models.CharField(max_length=100, unique=False, null=True)
    stu_age = models.IntegerField(unique=False, null=True)
    stu_college = models.CharField(max_length=100, unique=False, null=True)
    stu_major = models.CharField(max_length=100, unique=False, null=True)
    avatar = models.CharField(max_length=100, blank=True, null=True, verbose_name='用户头像')
    stu_borrowNum = models.IntegerField(unique=False, null=True)
    stu_phoneCode = models.CharField(max_length=6, blank=True, null=True) # 手机验证码
    stu_codeAcquireTime = models.DateTimeField(max_length=50, null=True) # 验证码获取时间


class Admin(models.Model):
    # id = models.IntegerField(primary_key=True)
    adm_id = models.IntegerField(primary_key=True)
    adm_pwd = models.CharField(max_length=100, unique=False)
    adm_phone = models.CharField(max_length=11, unique=True)
    adm_name = models.CharField(max_length=100, unique=True)
    adm_phoneCode = models.CharField(max_length=6, blank=True, null=True)  # 手机验证码
    adm_codeAcquireTime = models.DateTimeField(max_length=50, null=True)  # 验证码获取时间


class Book(models.Model):
    book_id = models.IntegerField(primary_key=True)
    admId = models.ForeignKey('Admin', on_delete=models.CASCADE)
    book_name = models.CharField(max_length=100, unique=True)
    book_author = models.CharField(max_length=100, unique=False)
    book_pubDate = models.DateField(unique=False)
    book_publisher = models.CharField(max_length=100, unique=False)
    book_price = models.FloatField(unique=False)
    book_num = models.IntegerField(unique=False)
    book_total = models.IntegerField(unique=False)
    book_intro = models.TextField(max_length=200)
    book_img = models.CharField(max_length=100, blank=True, null=True, verbose_name='书籍图片')


class Borrow(models.Model):
    borrow_id = models.AutoField(primary_key=True)
    stuId = models.ForeignKey('Student', on_delete=models.CASCADE)
    bookId = models.ForeignKey('Book', on_delete=models.CASCADE)
    borrow_date = models.DateField(unique=False)
    due_date = models.DateField(unique=False)
    return_date = models.DateField(unique=False, null=True)
    isReturn = models.BooleanField(default=False)


class Notice(models.Model):
    notice_id = models.AutoField(primary_key=True)
    admId = models.ForeignKey('Admin', on_delete=models.CASCADE)
    notice_title = models.CharField(max_length=100, unique=False)
    notice_content = models.TextField(max_length=200)
    notice_date = models.DateField(unique=False)
